'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceBackdepositapplyCtrl
 * @description
 * # FinanceBackdepositapplyCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceBackdepositapplyCtrl', function($scope, $rootScope, openApi, $http, $filter, Util, $location, $routeParams, localStorageService, FormSubmit) {
        // 底部款项类型选框添加
        var selectData, params, relModuleObj = {};
        var payWayList = [{
            key: "银行保函",
            value: 1
        }, {
            key: "柜台转账",
            value: 2
        }, {
            key: "网银转账",
            value: 3
        }, {
            key: "银行汇票",
            value: 4
        }];

        $scope.sheetObj = {};
        // 底部款项类型选框添加
        // -------------------------------------------------------------------
        // 底部付款方式选框添加
        var paywayObj = {};
        paywayObj.sheettitle = "付款方式";
        paywayObj.tabList = payWayList;
        paywayObj.callback = function(item) {
            $scope.param.payWay = item.selectTab
            $scope.param.payWayContent = item.selectTabContent
        }
        $scope.sheetObj.paywayObj = paywayObj;
        // -------------------------------------------------------------------

        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type];
            $scope.sheetObj.type = type;
            $scope.sheetObj.oldValue = sheetObj.selectTab;
            $scope.sheetObj.tabList = sheetObj.tabList;
            $scope.sheetObj.sheettitle = sheetObj.sheettitle;
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };
        // -------------------------------------------------------------------

        $scope.disabled = function() {
            var checked = true;
            if (!$scope.param) {
                return
            }
            if ($scope.param.payType == 3) {
                checked = false;
            }
            return checked
        };
        $scope.submit = function() {
            // 底部类型end
            // $scope.param.tentativeCost = "11";
            if (!$scope.param.payWay) {
                Util.Toast("请选择付款方式");
                return;
            }
            if (!$scope.param.receiveMoney) {
                if ($scope.param.receiveMoney !== 0) {
                    Util.Toast("请填写收款金额");
                    return;
                }
            }
            if (!$scope.param.endDate) {
                Util.Toast("请选择到账截至日期");
                return;
            }
            if (!$scope.param.remark) {
                Util.Toast("请填写转账说明");
                return;
            }

            $scope.param.receiveDetail = angular.toJson($scope.param.receiveList)
                // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.depositApply
            var options = {};
            options.urlParam = urlParam;
            var myDest = {};
            options.param = angular.copy($scope.param, myDest);
            // 如果是修改页面的话则提交的地址不一样，参数一样
            delete options.param.fundSoruceList
            delete options.param.receiveList
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            if (TVtype == Util.UPDATE) {
                options.param["formBidApply.formId"] = options.param.formBidApply && options.param.formBidApply.formId || "";
                options.url = openApi.ip + openApi.depositApply
            }
            delete options.param.formBidApply
            new FormSubmit(options);
        };
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
                $scope.param.payType = 3;
                $scope.param.payWayContent = Util.getkeyFromValue(payWayList, $scope.param.payWay);
                // 根据后台返回的字符串创建列表，后台没有返回的话就初始化一个列表
                $scope.param.receiveList = $scope.param.receiveDetail && JSON.parse($scope.param.receiveDetail) || [];
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });

        };
        // 初始化
        init();
    });
